package com.java.zhuiyun.api.front_desk_user.mapper;

import com.java.zhuiyun.api.alipay.controller.AliPay;
import com.java.zhuiyun.api.front_desk_user.entity.FrontDeskUser;
import com.java.zhuiyun.api.front_desk_user.model.FrontDeskUserModels;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @InterfaceName FrontDeskUserMapper
 * @Description TODO 前台用户管理mapper层
 * @Author wuwan
 * @Date 2023/8/14 20:19
 **/
@Mapper
public interface FrontDeskUserMapper {
    /*
    * @Author wuwan
    * @Description 前台用户分页数据查询
    * @Date 2023/8/15 16:24
    * @Return
    * @param null
    */
    @Select("select id,front_desk_name,front_desk_account,front_desk_member,front_desk_member_time,front_desk_phone,front_desk_email,create_time,update_time,account_type,ban_time,img " +
            "from front_desk_user " +
            "where del_flag = 0 " +
            "and front_desk_name like concat('%',#{frontDeskName},'%')" +
            "or front_desk_email like  concat('%',#{frontDeskName},'%')" +
            "or front_desk_phone like  concat('%',#{frontDeskName},'%')")
    List<FrontDeskUser> getFrontDeskUser(String frontDeskName);

    /*
    * @Author wuwan
    * @Description 定时任务解封
    * @Date 2023/8/15 16:24
    * @Return
    * @param null
    */
    @Update("update front_desk_user set  account_type = 0,ban_time = null where ban_time<Now() and account_type =1")
    Integer updateAccount();
    /*
    * @Author wuwan
    * @Description 手动账号解封
    * @Date 2023/8/15 16:24
    * @Return
    * @param null
    */
    @Update("update front_desk_user set  account_type = 0,ban_time = null where account_type =1 and id=#{id}")
    Integer updateAccountRelease(Integer id);

    /*
    * @Author wuwan
    * @Description 账号封禁
    * @Date 2023/8/15 16:25
    * @Return
    * @param null
    */
    @Update("update front_desk_user set  account_type = 1,ban_time=#{banTime} where id=#{id}")
    Integer updateFrontDeskUser(Integer id, Date banTime);

    @Select("select id,front_desk_name,front_desk_account,front_desk_member,front_desk_member_time,front_desk_phone,front_desk_email,create_time,update_time,account_type,ban_time,img" +
            " from front_desk_user where id=#{id}")
    FrontDeskUser queryById(Integer id);

    /*
     * @Author WX
     * @Description 修改用户会员状态
     * @Date 2023/8/31 10:08
     * @Return
     * @param aliPay
     */
    @Update("UPDATE front_desk_user SET front_desk_member = #{memberId} , front_desk_member_time = #{expiryTime} WHERE  id = #{userId}")
    int updateMember(AliPay aliPay);

    /*
     * @Author WX
     * @Description 查询个人信息
     * @Date 2023/8/31 9:00
     * @Return
     * @param id
     */
    @Select("SELECT * FROM front_desk_user WHERE id = #{id}")
    FrontDeskUser selectUserbyId(Integer id);
    /*
     * @Author WX
     * @Description 修改个人信息
     * @Date 2023/8/31 9:00
     * @Return
     * @param FrontDeskUser MultipartFile
     */
    @Update("update front_desk_user set front_desk_name = #{frontDeskName},region = #{region},img = #{img} WHERE id = #{id} ")
    int updateUserById(FrontDeskUser frontDeskUser);

    /*
    * @Author WX
    * @Description 查询个人会员信息
    * @Date 2023/8/31 9:04
    * @Return
    * @param id
    */
    @Select("SELECT * FROM  front_desk_user f,member_type m WHERE f.front_desk_member = m.id AND f.id =#{id}")
    FrontDeskUserModels getUserMemberManager(Integer id);

    /*
     * @Author WX
     * @Description 查询登录用户头像
     * @Date 2023/8/31 9:01
     * @Return
     * @param id
     */
    @Select("SELECT img FROM front_desk_user WHERE id =#{id}")
    Integer getFrontUserImg(Integer id);

    @Select("SELECT * FROM front_desk_user WHERE id = #{userId}")
    FrontDeskUser findTimeByUserId(Integer userId);

    /*
     * @Author WX
     * @Description 查询邮箱
     * @Date 2023/9/1 9:44
     * @Return
     * @param null
     */
    @Select("SELECT  * FROM front_desk_user WHERE front_desk_email = #{frontDeskEmail}")
    FrontDeskUser findByFrontDeskEmail(String frontDeskEmail);

    /*
     * @Author WX
     * @Description 查询手机
     * @Date 2023/9/1 9:44
     * @Return
     * @param null
     */
    @Select("SELECT  * FROM front_desk_user WHERE front_desk_phone = #{frontDeskPhone}")
    FrontDeskUser findByFrontDeskPhone(String frontDeskPhone);

    /*
     * @Author WX
     * @Description 修改手机
     * @Date 2023/9/1 9:44
     * @Return
     * @param null
     */
    @Update("update front_desk_user set front_desk_phone = #{frontDeskPhone} WHERE id = #{id} ")
    int updateUserByPhone(FrontDeskUser frontDeskUser);

    /*
     * @Author WX
     * @Description 修改邮箱
     * @Date 2023/9/1 9:44
     * @Return
     * @param null
     */
    @Update("update front_desk_user set front_desk_email = #{frontDeskEmail} WHERE id = #{id} ")
    int updateUserByEmail(FrontDeskUser frontDeskUser);
}
